﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using DAL.App_Code;

namespace DAL.DataOperate
{
    public class ManagerDAL:DAL.App_Code.DBBase
    {
        public ManagerDAL() : base() { }

        #region 查找
        public DataSet SelectAll()
        {
            StringBuilder sqlStr = new StringBuilder();
            DataSet ds = new DataSet();

            sqlStr.Append("select * from vi_Manager");

            SqlParameter[] pa = { };

            return ExecuteString(sqlStr.ToString(), pa, "tbManager_Infor");
        }
        public DataSet SelectByName(String ManagerName)
        {
            StringBuilder sqlStr = new StringBuilder();
            DataSet ds = new DataSet();
            sqlStr.Append("select Manager_Passwordstr,Manager_Namestr from vi_Manager ");
            sqlStr.Append("where Manager_Namestr = ");
            sqlStr.Append("@ManagerName");


            SqlParameter[] pa = { 
               new SqlParameter ("@ManagerName",ManagerName)
                               };

            return ExecuteString(sqlStr.ToString(), pa, "tbManager_Infor");
        }
        public DataSet SelectByID(int ManagerId)
        {
            StringBuilder sqlStr = new StringBuilder();
            DataSet ds = new DataSet();

            sqlStr.Append("select * from vi_Manager ");
            sqlStr.Append("where Manager_Idint = ");
            sqlStr.Append("@Manager_Idint");

            SqlParameter[] pa = { 
                                new SqlParameter("@Manager_Idint",ManagerId)
                                };

            return ExecuteString(sqlStr.ToString(), pa, "tbManager_Infor");
        }
        #endregion

        #region 增删改
        public bool Insert(Model.Manager manager)
        {
            int affectedRow = 0;
            int returnValue = 0;

            SqlParameter[] pa={
              new SqlParameter("@Manager_Namestr",manager.Manager_Namestr),
              new SqlParameter("@Manager_Passwordstr",manager.Manager_Passwordstr)
                              };

            returnValue = ExecuteRetProcedure("sp_InsertManager", pa, out affectedRow);
            return returnValue > 0 ? true : false;
        }
        public bool Update(Model.Manager manager)
        {
            int affectedRow = 0;
            int returnValue = 0;

            SqlParameter[] pa ={
              new SqlParameter("@Manager_Namestr",manager.Manager_Namestr),
              new SqlParameter("@Manager_Passwordstr",manager.Manager_Passwordstr)
                              };
            returnValue = ExecuteRetProcedure("sp_UpdateManager", pa, out affectedRow);
            return returnValue > 0 ? true : false;
        }
        public bool Delete(int ManagerId)
        {
            StringBuilder sqlStr = new StringBuilder();
            int affectedRow = 0;

            sqlStr.Append("delete from vi_Manager ");
            sqlStr.Append("where Manager_Idint = ");
            sqlStr.Append("@Manager_Idint");
            SqlParameter[] pa = {
                   new SqlParameter("@Manager_Idint",ManagerId)
                                };
            ExecuteString(sqlStr.ToString(), pa, out affectedRow);
            return affectedRow > 0 ? true : false;
        }
        #endregion 

    }
}
